package cn.drh.charging.cost.config;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;

import java.io.Serializable;

/**
 * @ClassName RedisConfiguration
 * @Description redis配置类
 * @Author renhong~Deng
 * @Date 2025/6/11 11:39
 * @Version 1.0
 */

@Configuration
public class RedisConfiguration {

    /**
     * redis需要序列化
     * @param redisConnectionFactory redis连接工厂
     * @return
     */
    @Bean
    public RedisTemplate<String, Serializable> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
        RedisTemplate<String, Serializable> redisTemplate = new RedisTemplate<>();
        //设置连接工厂
        redisTemplate.setConnectionFactory(redisConnectionFactory);
        //设置key的序列号器
        redisTemplate.setKeySerializer(RedisSerializer.string());
        //设置value的序列号器
        redisTemplate.setValueSerializer(RedisSerializer.json());
        return redisTemplate;
    }
}
